<?php
$title='充值余额';
include './head.php';
if($_GET['do']=="cz" && $_POST['type']=="cz"){
	$km = daddslashes($_POST['km']);
	if(!$km)
		exit("<script>alert('卡密不能为空');history.go(-1);</script>");
	$kmrow=$DB->get_row("SELECT * FROM tell_kms WHERE km='$km' limit 1");
	if(!$kmrow['id'])
		exit("<script>alert('卡密不存在，请重新输入');history.go(-1);</script>");
	if($kmrow['isuse']==1)
		exit("<script>alert('卡密已被使用');history.go(-1);</script>");
	$ms = $kmrow['value'];
	$sql = "update tell_users set money=money+$ms where id='{$userrow['id']}'";
	if($DB->query($sql)){
			$DB->query("update tell_kms set isuse='1',user='{$userrow['phone']}',usetime='$date' where id='{$kmrow['id']}'");
			exit("<script>alert('充值成功');history.go(-1);</script>");
			
			}else{
				exit("<script>alert('充值失败');history.go(-1);</script>");
				}
}
?>
  <div class="container" style="padding-top:70px;">
    <div class="col-xs-12 col-sm-10 col-lg-8 center-block" style="float: none;">
      <div class="panel panel-primary">
        <div class="panel-heading"><h3 class="panel-title">网站公告</h3></div>
          <?=$conf['gg']?>
      </div>
<div class="panel panel-info">
	<div class="panel-heading">
		<h3 class="panel-title">充值余额</h3>
	</div>
	<ul class="list-group">
		<li class="list-group-item">
			<b>卡密：</b>
		</li>
        <li class="list-group-item">
        <form action="?do=cz" method="post" class="form-horizontal" >
        	<input type="hidden" name="type" value="cz" />
			<input type="text" name="km" class="form-control" required/>
        </li>
        <li class="list-group-item">
            <input type="submit" name="submit" value="充值" class="btn btn-primary form-control"/>
         </form>
        </li>
	</ul>
</div>
    </div>
  </div>
  